package edu.hcmus.sow.domain;

import java.io.Serializable;
import java.util.Calendar;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllUserProfiles", query = "select myUserProfile from UserProfile myUserProfile"),
		@NamedQuery(name = "findUserProfileByAvatar", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.avatar = ?1"),
		@NamedQuery(name = "findUserProfileByBirthday", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.birthday = ?1"),
		@NamedQuery(name = "findUserProfileByCreatedDate", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.createdDate = ?1"),
		@NamedQuery(name = "findUserProfileByEmail", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.email = ?1"),
		@NamedQuery(name = "findUserProfileByEmailContaining", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.email like ?1"),
		@NamedQuery(name = "findUserProfileByFirstName", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.firstName = ?1"),
		@NamedQuery(name = "findUserProfileByFirstNameContaining", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.firstName like ?1"),
		@NamedQuery(name = "findUserProfileById", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.id = ?1"),
		@NamedQuery(name = "findUserProfileByLastName", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.lastName = ?1"),
		@NamedQuery(name = "findUserProfileByLastNameContaining", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.lastName like ?1"),
		@NamedQuery(name = "findUserProfileByLastSigned", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.lastSigned = ?1"),
		@NamedQuery(name = "findUserProfileByMiddleName", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.middleName = ?1"),
		@NamedQuery(name = "findUserProfileByMiddleNameContaining", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.middleName like ?1"),
		@NamedQuery(name = "findUserProfileByPhone", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.phone = ?1"),
		@NamedQuery(name = "findUserProfileByPhoneContaining", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.phone like ?1"),
		@NamedQuery(name = "findUserProfileByPrimaryKey", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.id = ?1"),
		@NamedQuery(name = "findUserProfileByUpdatedDate", query = "select myUserProfile from UserProfile myUserProfile where myUserProfile.updatedDate = ?1") })
@Table(catalog = "sow", name = "user_profile")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "UserProfile")
public class UserProfile implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "FIRST_NAME", length = 50, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String firstName;
	/**
	 */

	@Column(name = "MIDDLE_NAME", length = 50)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String middleName;
	/**
	 */

	@Column(name = "LAST_NAME", length = 50, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String lastName;
	/**
	 */

	@Column(name = "AVATAR")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer avatar;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "BIRTHDAY")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar birthday;
	/**
	 */

	@Column(name = "PHONE", length = 15)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String phone;
	/**
	 */

	@Column(name = "EMAIL", length = 30)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String email;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "LAST_SIGNED")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar lastSigned;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATED_DATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar createdDate;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "UPDATED_DATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar updatedDate;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "USER_ID", referencedColumnName = "ID", unique = true, nullable = false) })
	@XmlTransient
	User userByUserId;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "CREATED_BY", referencedColumnName = "ID") })
	@XmlTransient
	User userByCreatedBy;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "UPDATED_BY", referencedColumnName = "ID") })
	@XmlTransient
	User userByUpdatedBy;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 */
	public String getFirstName() {
		return this.firstName;
	}

	/**
	 */
	public void setMiddleName(String middleName) {
		this.middleName = middleName;
	}

	/**
	 */
	public String getMiddleName() {
		return this.middleName;
	}

	/**
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 */
	public String getLastName() {
		return this.lastName;
	}

	/**
	 */
	public void setAvatar(Integer avatar) {
		this.avatar = avatar;
	}

	/**
	 */
	public Integer getAvatar() {
		return this.avatar;
	}

	/**
	 */
	public void setBirthday(Calendar birthday) {
		this.birthday = birthday;
	}

	/**
	 */
	public Calendar getBirthday() {
		return this.birthday;
	}

	/**
	 */
	public void setPhone(String phone) {
		this.phone = phone;
	}

	/**
	 */
	public String getPhone() {
		return this.phone;
	}

	/**
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 */
	public String getEmail() {
		return this.email;
	}

	/**
	 */
	public void setLastSigned(Calendar lastSigned) {
		this.lastSigned = lastSigned;
	}

	/**
	 */
	public Calendar getLastSigned() {
		return this.lastSigned;
	}

	/**
	 */
	public void setCreatedDate(Calendar createdDate) {
		this.createdDate = createdDate;
	}

	/**
	 */
	public Calendar getCreatedDate() {
		return this.createdDate;
	}

	/**
	 */
	public void setUpdatedDate(Calendar updatedDate) {
		this.updatedDate = updatedDate;
	}

	/**
	 */
	public Calendar getUpdatedDate() {
		return this.updatedDate;
	}

	/**
	 */
	public void setUserByUserId(User userByUserId) {
		this.userByUserId = userByUserId;
	}

	/**
	 */
	@JsonIgnore
	public User getUserByUserId() {
		return userByUserId;
	}

	/**
	 */
	public void setUserByCreatedBy(User userByCreatedBy) {
		this.userByCreatedBy = userByCreatedBy;
	}

	/**
	 */
	@JsonIgnore
	public User getUserByCreatedBy() {
		return userByCreatedBy;
	}

	/**
	 */
	public void setUserByUpdatedBy(User userByUpdatedBy) {
		this.userByUpdatedBy = userByUpdatedBy;
	}

	/**
	 */
	@JsonIgnore
	public User getUserByUpdatedBy() {
		return userByUpdatedBy;
	}

	/**
	 */
	public UserProfile() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(UserProfile that) {
		setId(that.getId());
		setFirstName(that.getFirstName());
		setMiddleName(that.getMiddleName());
		setLastName(that.getLastName());
		setAvatar(that.getAvatar());
		setBirthday(that.getBirthday());
		setPhone(that.getPhone());
		setEmail(that.getEmail());
		setLastSigned(that.getLastSigned());
		setCreatedDate(that.getCreatedDate());
		setUpdatedDate(that.getUpdatedDate());
		setUserByUserId(that.getUserByUserId());
		setUserByCreatedBy(that.getUserByCreatedBy());
		setUserByUpdatedBy(that.getUserByUpdatedBy());
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("firstName=[").append(firstName).append("] ");
		buffer.append("middleName=[").append(middleName).append("] ");
		buffer.append("lastName=[").append(lastName).append("] ");
		buffer.append("avatar=[").append(avatar).append("] ");
		buffer.append("birthday=[").append(birthday).append("] ");
		buffer.append("phone=[").append(phone).append("] ");
		buffer.append("email=[").append(email).append("] ");
		buffer.append("lastSigned=[").append(lastSigned).append("] ");
		buffer.append("createdDate=[").append(createdDate).append("] ");
		buffer.append("updatedDate=[").append(updatedDate).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof UserProfile))
			return false;
		UserProfile equalCheck = (UserProfile) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
